import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


/**
 * This class is TO Add Class To Course UI
 */
public class AddParentUI  extends JPanel {
	/**
	 * Label for parent id
	 */
	private JLabel lblUserID = null;
	/**
	 * Label for child id
	 */
	private JLabel lblCID = null;
	/**
	 * Label for parent password
	 */
	private JLabel lblUserPass = null;
	/**
	 * Label for parent name
	 */
	private JLabel lblUserName = null;
	/**
	 * title for the current window  
	 */
	private JLabel lbltitle = null;
	/**
	 * button for add parent 
	 */
	private JButton btnAddParent = null;
	/**
	 * button for delete parent 
	 */
	private JButton btnDelParent = null;
	/**
	 * text field for parent id 
	 */
	private JTextField pIdText = null;
	/**
	 * text field for child id 
	 */
	private JTextField cIdText = null;
	/**
	 * text field for password 
	 */
	private JTextField PassText = null;
	/**
	 * text field for name 
	 */
	private JTextField nameText = null;
	/**
	 * back button 
	 */
	public JButton btnBack = null;
	/**
	 * help button 
	 */
	public JButton btnHelp = null;
	/**
	* Variables to set the input from the gui to the control
	*/
	private String pID;
	private String name;
	private String pass;
	private String cID;
	/**
	* Constructs 
	*/
	public AddParentUI() {
		super();
		initialize();
	}

	private void initialize() {
		System.out.println("init AddParentUI");
		btnAddParent = new JButton();
		/**
		 *  add parent Implementation
		 */
		btnAddParent.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				AddParent addParent = new AddParent(pID,pass,cID,name);
				SQL s = new SQL(addParent,5);
				s.accept();
			}
		});
		btnAddParent.setBounds(new Rectangle(71, 226, 128, 31));
		btnAddParent.setText("Add New Parent");
		this.add(btnAddParent,null);
		
		
		pIdText = new JTextField();
		pIdText.setBounds(new Rectangle(154, 69, 128, 25));
		pIdText.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				pID=pIdText.getText();			
			}
		}
		);
	
		this.add(pIdText,null);
		
		nameText = new JTextField();
		nameText.setBounds(new Rectangle(154, 179, 128, 25));
		nameText.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				name=nameText.getText();			
			}
		}
		);
	
		this.add(nameText,null);
		
		
		cIdText = new JTextField();
		cIdText.setBounds(new Rectangle(154, 140, 128, 25));
		cIdText.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				cID=cIdText.getText();			
			}
		}
		);
	
		this.add(cIdText,null);
		
		
		PassText = new JTextField();
		PassText.setBounds(new Rectangle(154, 105, 128, 25));
		PassText.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				pass=PassText.getText();			
			}
		}
		);
		this.add(PassText,null);
		
		this.setVisible(true);
		
		
		

		lblUserID = new JLabel("Parent ID:");
		lblUserID.setBounds(83, 74, 110, 14);
		this.add(lblUserID);	
		
		lblCID = new JLabel("Child ID:");
		lblCID.setBounds(83, 144, 110, 14);
		this.add(lblCID);	
		
		
		lblUserPass = new JLabel("Password:");
		lblUserPass.setBounds(83, 110, 110, 14);
		this.add(lblUserPass);
		
		
		lblUserName = new JLabel("Name:");
		lblUserName.setBounds(83, 170, 110, 14);
		this.add(lblUserName);
		

		lbltitle = new JLabel("Add New Parent");
		lbltitle.setBounds(172, 26, 110, 14);
		this.add(lbltitle);
		
		this.setSize(400, 321);
		this.setLayout(null);

	
		btnBack = new JButton("Back");
		btnBack.setBounds(169, 280, 86, 25);
		this.add(btnBack,null);
		this.setVisible(true);
		/**
		 *  help button Implementation
		 */
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Enter Parent detalis and child ID and then click on","'Add New Parent' or 'Delete Parent' button");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);
		

		btnDelParent = new JButton();
		/**
		 *  delete parent Implementation
		 */
		btnDelParent.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				User use = new User(pID,pass);
				SQL s = new SQL(use,11);
				s.accept();
			}
		});
		btnDelParent.setText("Delete Parent");
		btnDelParent.setBounds(new Rectangle(68, 210, 110, 31));
		btnDelParent.setBounds(235, 226, 121, 31);
		this.add(btnDelParent);
		this.setVisible(true);
		
	}
	

}
